<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<body>
<div id="app">
    <el-card>
        <h1>这是卡片组件</h1>
    </el-card>
    <!--action代表提交地址,name代表文件上传时的参数名称-->
    <el-upload
            action="/upload"
            name="picFile"
            list-type="picture-card"
            :on-preview="handlePictureCardPreview"
            :on-remove="handleRemove">
        <i class="el-icon-plus"></i>
    </el-upload>

    <el-dialog :visible.sync="dialogVisible">
        <img width="100%" :src="dialogImageUrl" alt="">
    </el-dialog>
</div>
</body>
<!--引入Vue框架-->
<script src="https://unpkg.com/vue@2.6.14/dist/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<!--引入axios-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script>
   let v = new Vue({
        el: '#app',
        data: function() {
            return {
                dialogImageUrl: '',
                dialogVisible: false
            }
        },
       methods: {
           handleRemove(file, fileList) {
               console.log(file, fileList);
               //发请求告诉服务器删除文件夹里面的文件
               //得到要删除的文件
               let fileName=file.response;//element-ui中规定的获取数据
               console.log("文件名"+fileName);
               axios.get("/remove?fileName="+fileName).then(function (){
                   console.log("服务器文件删除完成!")
               })

           },
           handlePictureCardPreview(file) {
               this.dialogImageUrl = file.url;
               this.dialogVisible = true;
           }
       }
    })
</script>
</html>